package edu.whu.rose.clock.kps.spindex;

import com.sleepycat.je.DatabaseException;

import edu.whu.rose.clock.setup.IndexEnvironment;

public class ShortestPathIndexTester {

	public static void main(String[] args) {
		IndexEnvironment ie = new IndexEnvironment("dbEnv_shortestpath");
		if (!ie.openEnv()) {
			System.exit(1);
		}
		
		ShortestPathIndexDB disDB = new ShortestPathIndexDB(ie.getEnvironment(), "distances");
		ShortestPathIndexDB preDB = new ShortestPathIndexDB(ie.getEnvironment(), "predecessors");
		disDB.openDB();
		preDB.openDB();
		
		try {
			int subgraph = 94208;
			int source = 22186;
			
			int[] distances = disDB.search(subgraph, source);
			int[] predecessors = preDB.search(subgraph, source);
			System.out.println("distances:");
			for (int i = 0; i < distances.length; i++) {
				System.out.print(distances[i] + " ");
			}
			System.out.println();
			System.out.println("predecessors:");
			for (int i = 0; i < predecessors.length; i++) {
				System.out.print(predecessors[i] + " ");
			}
			System.out.println();
//			int end = 19;
//			System.out.println("from " + source + " to " + end + ": ");
//			System.out.println("shortest distance: " + distances[end]);
//			System.out.print("shortest path: " + end);
//			while (end != source) {
//				end = predecessors[end] - 1;
//				System.out.print(end + " ");
//			}
//			System.out.println(source);
		}
		catch (DatabaseException ex) {
			ex.printStackTrace();
		}
		
		disDB.closeDB();
		preDB.closeDB();
		ie.closeEnv();
	}

}
